<style lang="scss">
  /* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
  @import "@/uni_modules/uview-ui/index.scss";
</style>

<script>
  import croods from '@/common/croods-1.3.3.js';
  window.croods = croods;
  window.hydra = require('@/common/wst_hydra-1.0.0.js');
  import {
    mapState
  } from 'vuex';
  import {
    getToken2
  } from '@/common/api.js';
  export default {
    computed: {
      ...mapState(['loginStatus', 'appVersion', 'loginMsg', 'isLogin', 'wsToken', 'nextUpdateToken',
        'loginUserIdentity']),
    },
    data() {
      return {
        passStatus: false
      }
    },
    methods: {
      /* 新 */
      loginVersionTwo() {
        let that = this

        /* 测试环境1 */
        // setTimeout(function() {
        // 	that.$store.commit('changeWsToken', "6444736ee8b0475c824c3e7f5747a062")
        // 	that.$store.commit('changeNextUpdateToken', Date.now()+1200000)
        // 	that.$store.commit('changeLoginUserIdentity', true)	
        // 	that.$store.commit('loginStatusChange', true)
        // 	that.$store.commit('isLoginChange', true)
        // 	uni.switchTab({
        // 		url: '/pages/hmss/index',
        // 	})
        // }, 500)

        /* 测试环境2 */
        getToken2({
          wstoken: "862d44f0355847e5b4f5ac8f9541c107"
        }).then(resL => {
          that.$store.commit('changeWsToken', "862d44f0355847e5b4f5ac8f9541c107")
          that.$store.commit('changeNextUpdateToken', Date.now() + 1200000)
          that.$store.commit('changeLoginUserIdentity', true)
          that.$store.commit('loginStatusChange', true)
          that.$store.commit('isLoginChange', true)
        })


        /* 正式环境 */
        // window.croods.customPlugin({
        //   action: "UserPlugin.login",
        //   params: {},
        //   success: function(res) {
        //     alert(JSON.stringify(res.token))
        //     that.passStatus = true
        //     getToken2({
        //       wstoken: res.token
        //     }).then(resL => {
        //       that.$store.commit('changeWsToken', res.token)
        //       that.$store.commit('changeNextUpdateToken', Date.now() + 1200000)
        //       if (resL.status) {
        //         that.$store.commit('loginStatusChange', true)
        //         that.$store.commit('isLoginChange', true)
        //         that.$store.commit('getLoginMsg', resL.code)
        //         that.$store.commit('changeLoginUserIdentity', true)
        //       } else {
        //         that.$store.commit('loginStatusChange', false)
        //         that.$store.commit('isLoginChange', true)
        //         that.$store.commit('getLoginMsg', resL.code)
        //         that.$store.commit('changeLoginUserIdentity', false)
        //       }
        //     }).catch(fail => {
        //       that.$store.commit('loginStatusChange', false)
        //       that.$store.commit('isLoginChange', true)
        //       that.$store.commit('getLoginMsg', "")
        //       that.$store.commit('changeWsToken', "")
        //       that.$store.commit('changeNextUpdateToken', Date.now() + 1200000)
        //       that.$store.commit('changeLoginUserIdentity', false)
        //     })
        //   }
        // })
      }

    },
    created() {
      if (this.appVersion == 'X2') {
        this.loginVersionTwo()
      }
    },
  }
</script>

<style lang="scss">
  /* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
  @import "@/uni_modules/uview-ui/index.scss";

  page {
    background-color: #FAFAFA;
  }

  /*每个页面公共css */
  .u-page {
    background-color: white;
    padding: 5px;
  }
</style>